﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using static Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary;

namespace AspNetIdentity.Models
{
    /// <summary>
    /// 通用返回信息类
    /// </summary>
    public class ResultMessageModel<T>
    {
        /// <summary>
        /// 状态码
        /// </summary>
        public int status { get; set; } = 200;
        /// <summary>
        /// 操作是否成功
        /// </summary>
        public bool success { get; set; } = false;
        /// <summary>
        /// 返回信息
        /// </summary>
        public string msg { get; set; } = "服务器异常";
        /// <summary>
        /// 返回数据集合
        /// </summary>
        public T response { get; set; }
        /// <summary>
        /// 返回Error集合
        /// </summary>
        public List<string> Errors { get; set; }

    }
    public static class ModelValid
    {
        public static List<string> ErrorMessageList(ValueEnumerable values)
        {
            var result = new List<string>();
            foreach (var item in values)
            {
                if (item.Errors.Count > 0)
                {
                    foreach(var err in item.Errors)
                    {
                        result.Add(err.ErrorMessage);
                    }
                }
            }
            return result;
        }
    }
}
